package com.itheima.api.generic.demo07;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class GeneriDemo07 {

    public static void main(String[] args) {

        ArrayList<Animal> animals = new ArrayList<Animal>();
        Animal a1 = new Animal("小白");
        Animal a2 = new Animal("小黑");
        animals.add(a1);
        animals.add(a2);
        show(animals);
        show1(animals);
        show2(animals);
        System.out.println("----------------------------");

        ArrayList<Cat> cats = new ArrayList<Cat>();
        show(cats);
        show1(cats);
//        show2(cats);
        System.out.println("-----------------------------");

        ArrayList<Object> objects = new ArrayList<Object>();
        show(objects);
//        show1(objects);
        show2(objects);
    }

    public static void show2(List<? super Animal> list){
        for (Object obj : list){
            System.out.println(obj);
        }
    }

    public static void show1(List<? extends Animal> list){
        Iterator<? extends Animal> iterator = list.iterator();
        while (iterator.hasNext()){
            System.out.println(iterator.next());
        }
    }

    public static void show(List<?> list){
        list.forEach(s -> System.out.println(s));
    }


}
